﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Dycox.Reporting.Aggregation
{
    internal class Count : AggregationContext
    {
        public Count(string dataMember)
            : base(dataMember)
        {

        }

        protected override bool RequiresDataMember
        {
            get
            {
                return false;
            }
        }

        int _count;

        protected override void Initialize()
        {
            base.Initialize();
            _count = 0;
        }

        private bool _countNullValues;

        public bool CountNullValues
        {
            get { return _countNullValues; }
            set { _countNullValues = value; }
        }


        protected override void Aggregate(object value, object dataObject, System.ComponentModel.PropertyDescriptor property)
        {
            if (DataMember != null)
            {
                if (value != null || _countNullValues) _count++;
            }
            else
            {
                if (dataObject != null) _count++;
            }
        }

        protected override object FinishAggregate()
        {
            return _count;
        }
    }
}
